#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 

int mdauth(int fd, char *vlogin, char *vheslo){
 
  char *command;
  char *response;  
  char *login, *heslo;
  
  if (vlogin == NULL)
  {
    fprintf(stderr, "login: login nesmie byt NULL\n");
    return 1;
  }
  else if (vheslo == NULL)
  {
    fprintf(stderr, "heslo: heslo nesmie byt NULL\n");
    return 1;
  }
  
  login = (char *) malloc(256*sizeof(char));
  heslo = (char *) malloc(256*sizeof(char));
  login = strncpy(login, vlogin, 255);
  heslo = strncpy(heslo, vheslo, 255);
  login[255] = '\0';
  heslo[255] = '\0';
  
  command = malloc(520*sizeof(char));
  sprintf(command, "AUTH %s %s\n", login, heslo);
  if (mdsend_command_and_get_response(fd, command, &response) == -1)
    return 1;
  else if (strstr(response, "200") == NULL)
  {
    fprintf(stderr, "%s", response);
    return 1;
  }
  else
    return 0;
}
